package com.imut.oa.controller.common;


import com.imut.oa.common.BaseResponse;
import com.imut.oa.common.ResultUtils;
import com.imut.oa.util.AliOssUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.UUID;

@RestController
public class FileUploadController {
    @PostMapping("/upload")
    public BaseResponse<String> upload(MultipartFile file) throws Exception {

        String originalFilename = file.getOriginalFilename();
        String filename = UUID.randomUUID().toString()+originalFilename.substring(originalFilename.lastIndexOf("."));
       // file.transferTo(new File("D:\\YRX\\project\\big-event\\big-event\\src\\main\\java\\com\\ysbt\\pic\\"+filename));
        String url = AliOssUtil.uploadFile(filename, file.getInputStream());
        return ResultUtils.success(url,"图片上传成功");
    }
}
